package com.ymk.cmd;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.rbac.RbacRoleBO;
import com.ymk.bo.rbac.RbacUserRoleBO;
import com.ymk.core.code.cmd.RbacCmdCode;

import com.ymk.service.IRbacUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class RbacUserRoleListCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        RbacRoleBO rbacRoleBO = super.getData(sign, RbacRoleBO.class);
        super.setCreatedData(sign,rbacRoleBO);

        return respSign;
    }

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        RbacUserRoleBO repData  = super.getData(sign,RbacUserRoleBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("mchId",repData.getMchId())
                .addParam("userId",repData.getUserId())
                .addParam("loadRole",true);

        List<RbacUserRoleBO> rbacUserRoleBO = this.rbacRoleUserService.list(paramsBuilder.build());

        respSign.setSource(super.getSource(rbacUserRoleBO));
        return respSign;
    }


    @Override
    public String getCmdCode() {
        return RbacCmdCode.RBAC_USER_ROLE_LIST;
    }

    @Autowired
    private IRbacUserRoleService rbacRoleUserService;

}
